import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_dialog_phys.dart';
import 'package:flutter_eve_plugin/constants/font_family.dart';
import 'package:flutter_eve_plugin/constants/font_weight.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/stageinfo.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/vitality.dart';
import 'package:flutter_eve_plugin/route/main.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_eve_plugin/utils/toast_util.dart';

class CheckpointBtnWidget extends StatelessWidget {
  final CheckpointStageInfo info;
  final DungeonVitality dungeonVitality;
  const CheckpointBtnWidget({Key key, this.info, this.dungeonVitality})
      : super(key: key);

  void showAlertDialog(BuildContext context) {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return CheckpointPhysDialog();
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(top: setRatio(8), left: setRatio(93)),
      child: GestureDetector(
        onTap: () {
          if ((info?.stageBasics?.usrInfo?.leftNum ?? 0) <= 0) {
            Toast.showYX(context, '次数不足');
          } else if ((info?.stageBasics?.configInfo?.vitality ?? 0) >
              (dungeonVitality?.currVitality ?? 0)) {
            showAlertDialog(context);
          } else {
            Navigator.popAndPushNamed(
                context, RouteConstant.CheckpointPrepareGamePage);
          }
        },
        child: Container(
          width: setRatio(160),
          height: setRatio(47),
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage(
                      (info?.stageBasics?.usrInfo?.leftNum ?? 0) <= 0
                          ? imageUtilYeXiu(
                              'checkpoint/icon_dialog_btn_enavailable@3x')
                          : imageUtilYeXiu(
                              'checkpoint/icon_dialog_btn_available@3x')))),
          child: Center(
            child: Text('前往挑战',
                style: TextStyle(
                    color: Color(0xFFFFFFFF),
                    fontFamily: FontFamily.PINGFANG,
                    fontWeight: FontWeightCustom.PF_Medium,
                    fontSize: setTextSp(17))),
          ),
        ),
      ),
    );
  }
}
